#-*-coding:utf8-*-
from django.http import HttpResponse
from Model.models import Order,TicketType
import json,time

def order(request):
    '''
    生成订单
    @author cxy
    '''
    if request.method == 'POST':
        count = request.POST['count']
        ticket_type_id = request.POST['id']
        wechat_id = request.POST['wechatId']
        order_birth_time = int(time.time())
        ticket_type = TicketType.objects.get(id=ticket_type_id)
        price = ticket_type.price
        sum_price = float(price) * float(count)
        order = Order(order_birth_time=order_birth_time,wechat_id=wechat_id,
        ticket_type_id=ticket_type_id,price=price,count=count,sum_price=sum_price)
        order.save()
        return HttpResponse(json.dumps({'code':200}, ensure_ascii=False), content_type="application/json;charset=utf8")
